// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyTopologyAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>
#include <visit-config.h>
#include <PyColorAttributeList.h>

// ****************************************************************************
// Module: PyTopologyAttributes
//
// Purpose:
//   This class contains the plot attributes for the topology plot
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a TopologyAttributes.
//
struct TopologyAttributesObject
{
    PyObject_HEAD
    TopologyAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewTopologyAttributes(int);
std::string
PyTopologyAttributes_ToString(const TopologyAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    snprintf(tmpStr, 1000, "%slineWidth = %d\n", prefix, atts->GetLineWidth());
    str += tmpStr;
    { const ColorAttributeList &cL = atts->GetMultiColor();
        const char *comment = (prefix==0 || strcmp(prefix,"")==0) ? "# " : "";
        for(int i = 0; i < cL.GetNumColors(); ++i)
        {
            const unsigned char *c = cL[i].GetColor();
            snprintf(tmpStr, 1000, "%s%sSetMultiColor(%d, (%d, %d, %d, %d))\n",
                     comment, prefix, i, int(c[0]), int(c[1]), int(c[2]), int(c[3]));
            str += tmpStr;
        }
    }
    snprintf(tmpStr, 1000, "%sminOpacity = %g\n", prefix, atts->GetMinOpacity());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sminPlateauOpacity = %g\n", prefix, atts->GetMinPlateauOpacity());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%smaxPlateauOpacity = %g\n", prefix, atts->GetMaxPlateauOpacity());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%smaxOpacity = %g\n", prefix, atts->GetMaxOpacity());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%stolerance = %g\n", prefix, atts->GetTolerance());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%shitpercent = %g\n", prefix, atts->GetHitpercent());
    str += tmpStr;
    return str;
}

static PyObject *
TopologyAttributes_Notify(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TopologyAttributes_SetLineWidth(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the lineWidth in the object.
    obj->data->SetLineWidth(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TopologyAttributes_GetLineWidth(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetLineWidth()));
    return retval;
}

/*static*/ PyObject *
TopologyAttributes_SetMultiColor(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;

    PyObject *pyobj = NULL;
    ColorAttributeList &cL = obj->data->GetMultiColor();
    int index = 0;
    int c[4] = {0,0,0,255};
    bool setTheColor = true;

    if(!PyArg_ParseTuple(args, "iiiii", &index, &c[0], &c[1], &c[2], &c[3]))
    {
        if(!PyArg_ParseTuple(args, "iiii", &index, &c[0], &c[1], &c[2]))
        {
            double dr, dg, db, da;
            if(PyArg_ParseTuple(args, "idddd", &index, &dr, &dg, &db, &da))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = int(da);
            }
            else if(PyArg_ParseTuple(args, "iddd", &index, &dr, &dg, &db))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = 255;
            }
            else
            {
                if(!PyArg_ParseTuple(args, "iO", &index, &pyobj))
                {
                    if(PyArg_ParseTuple(args, "O", &pyobj))
                    {
                        setTheColor = false;
                        if(PyTuple_Check(pyobj))
                        {
                            // Make sure that the tuple is the right size.
                            if(PyTuple_Size(pyobj) < cL.GetNumColors())
                                return PyErr_Format(PyExc_IndexError, "color tuple size=%d, expected=%d", (int) PyTuple_Size(pyobj), (int) cL.GetNumColors());

                            // Make sure that the tuple is the right size.
                            int *C = new int[4 * cL.GetNumColors()];
                            for(int i = 0; i < PyTuple_Size(pyobj); ++i)
                            {
                                PyObject *item = PyTuple_GET_ITEM(pyobj, i);
                                if(PyTuple_Check(item) &&
                                   (PyTuple_Size(item) == 3 || PyTuple_Size(item) == 4))
                                {
                                    C[i*4] = 0;
                                    C[i*4+1] = 0;
                                    C[i*4+2] = 0;
                                    C[i*4+3] = 255;
                                    for(int j = 0; j < PyTuple_Size(item); ++j)
                                    {
                                        PyObject *colorcomp = PyTuple_GET_ITEM(item, j);
                                        if(PyInt_Check(colorcomp))
                                           C[i*4+j] = int(PyInt_AS_LONG(colorcomp));
                                        else if(PyFloat_Check(colorcomp))
                                           C[i*4+j] = int(PyFloat_AS_DOUBLE(colorcomp));
                                        else
                                        {
                                           delete [] C;
                                           return PyErr_Format(PyExc_ValueError, "Unable to interpret component %d at index %d as a color component",j,i);
                                        }
                                    }
                                }
                                else
                                {
                                    delete [] C;
                                    return PyErr_Format(PyExc_ValueError, "Color tuple must be size 3 or 4");
                                }
                            }

                            for(int i = 0; i < cL.GetNumColors(); ++i)
                                cL[i].SetRgba(C[i*4], C[i*4+1], C[i*4+2], C[i*4+3]);
                            delete [] C;
                        }
                        else if(PyList_Check(pyobj))
                        {
                            // Make sure that the list is the right size.
                            if(PyList_Size(pyobj) < cL.GetNumColors())
                                return PyErr_Format(PyExc_IndexError, "color tuple size=%d, expected=%d", (int) PyTuple_Size(pyobj), (int) cL.GetNumColors());

                            // Make sure that the tuple is the right size.
                            int *C = new int[4 * cL.GetNumColors()];
                            for(int i = 0; i < PyList_Size(pyobj); ++i)
                            {
                                PyObject *item = PyList_GET_ITEM(pyobj, i);
                                if(PyTuple_Check(item) &&
                                   (PyTuple_Size(item) == 3 || PyTuple_Size(item) == 4))
                                {
                                    C[i*4] = 0;
                                    C[i*4+1] = 0;
                                    C[i*4+2] = 0;
                                    C[i*4+3] = 255;
                                    for(int j = 0; j < PyTuple_Size(item); ++j)
                                    {
                                        PyObject *colorcomp = PyTuple_GET_ITEM(item, j);
                                        if(PyInt_Check(colorcomp))
                                           C[i*4+j] = int(PyInt_AS_LONG(colorcomp));
                                        else if(PyFloat_Check(colorcomp))
                                           C[i*4+j] = int(PyFloat_AS_DOUBLE(colorcomp));
                                        else
                                        {
                                           delete [] C;
                                           return PyErr_Format(PyExc_ValueError, "Unable to interpret component %d at index %d as a color component",j,i);
                                        }
                                    }
                                }
                                else
                                {
                                    delete [] C;
                                    return PyErr_Format(PyExc_ValueError, "Color tuple must be size 3 or 4");
                                }
                            }

                            for(int i = 0; i < cL.GetNumColors(); ++i)
                                cL[i].SetRgba(C[i*4], C[i*4+1], C[i*4+2], C[i*4+3]);

                            delete [] C;
                        }
                        else
                            return PyErr_Format(PyExc_TypeError, "Expecting tuple or list");
                    }
                }
                else
                {
                    if(!PyTuple_Check(pyobj))
                        return NULL;

                    // Make sure that the tuple is the right size.
                    if(PyTuple_Size(pyobj) < 3 || PyTuple_Size(pyobj) > 4)
                        return PyErr_Format(PyExc_ValueError, "Color tuple must be size 3 or 4");

                    // Make sure that all elements in the tuple are ints.
                    for(int i = 0; i < PyTuple_Size(pyobj); ++i)
                    {
                        PyObject *item = PyTuple_GET_ITEM(pyobj, i);
                        if(PyInt_Check(item))
                            c[i] = int(PyInt_AS_LONG(PyTuple_GET_ITEM(pyobj, i)));
                        else if(PyFloat_Check(item))
                            c[i] = int(PyFloat_AS_DOUBLE(PyTuple_GET_ITEM(pyobj, i)));
                        else
                            return PyErr_Format(PyExc_ValueError, "Unable to interpret component %d as a color component", i);
                    }
                }
            }
        }
        PyErr_Clear();
    }

    if(index < 0 || index >= cL.GetNumColors())
        return PyErr_Format(PyExc_ValueError, "color index out of range 0 <= i < %d", (int) cL.GetNumColors());

    // Set the color in the object.
    if(setTheColor)
        cL[index] = ColorAttribute(c[0], c[1], c[2], c[3]);
    cL.SelectColors();
    obj->data->SelectMultiColor();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TopologyAttributes_GetMultiColor(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;
    PyObject *retval = NULL;
    ColorAttributeList &cL = obj->data->GetMultiColor();

    int index = 0;
    if(PyArg_ParseTuple(args, "i", &index))
    {
        if(index < 0 || index >= cL.GetNumColors())
            return NULL;

        // Allocate a tuple the with enough entries to hold the singleColor.
        retval = PyTuple_New(4);
        const unsigned char *c = cL.GetColors(index).GetColor();
        PyTuple_SET_ITEM(retval, 0, PyInt_FromLong(long(c[0])));
        PyTuple_SET_ITEM(retval, 1, PyInt_FromLong(long(c[1])));
        PyTuple_SET_ITEM(retval, 2, PyInt_FromLong(long(c[2])));
        PyTuple_SET_ITEM(retval, 3, PyInt_FromLong(long(c[3])));
    }
    else
    {
        PyErr_Clear();

        // Return the whole thing.
        retval = PyList_New(cL.GetNumColors());
        for(int i = 0; i < cL.GetNumColors(); ++i)
        {
            const unsigned char *c = cL.GetColors(i).GetColor();

            PyObject *t = PyTuple_New(4);
            PyTuple_SET_ITEM(t, 0, PyInt_FromLong(long(c[0])));
            PyTuple_SET_ITEM(t, 1, PyInt_FromLong(long(c[1])));
            PyTuple_SET_ITEM(t, 2, PyInt_FromLong(long(c[2])));
            PyTuple_SET_ITEM(t, 3, PyInt_FromLong(long(c[3])));

            PyList_SET_ITEM(retval, i, t);
        }
    }
    return retval;
}

/*static*/ PyObject *
TopologyAttributes_SetMinOpacity(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the minOpacity in the object.
    obj->data->SetMinOpacity(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TopologyAttributes_GetMinOpacity(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMinOpacity());
    return retval;
}

/*static*/ PyObject *
TopologyAttributes_SetMinPlateauOpacity(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the minPlateauOpacity in the object.
    obj->data->SetMinPlateauOpacity(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TopologyAttributes_GetMinPlateauOpacity(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMinPlateauOpacity());
    return retval;
}

/*static*/ PyObject *
TopologyAttributes_SetMaxPlateauOpacity(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the maxPlateauOpacity in the object.
    obj->data->SetMaxPlateauOpacity(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TopologyAttributes_GetMaxPlateauOpacity(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMaxPlateauOpacity());
    return retval;
}

/*static*/ PyObject *
TopologyAttributes_SetMaxOpacity(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the maxOpacity in the object.
    obj->data->SetMaxOpacity(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TopologyAttributes_GetMaxOpacity(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetMaxOpacity());
    return retval;
}

/*static*/ PyObject *
TopologyAttributes_SetTolerance(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the tolerance in the object.
    obj->data->SetTolerance(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TopologyAttributes_GetTolerance(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetTolerance());
    return retval;
}

/*static*/ PyObject *
TopologyAttributes_SetHitpercent(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the hitpercent in the object.
    obj->data->SetHitpercent(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
TopologyAttributes_GetHitpercent(PyObject *self, PyObject *args)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetHitpercent());
    return retval;
}



PyMethodDef PyTopologyAttributes_methods[TOPOLOGYATTRIBUTES_NMETH] = {
    {"Notify", TopologyAttributes_Notify, METH_VARARGS},
    {"SetLineWidth", TopologyAttributes_SetLineWidth, METH_VARARGS},
    {"GetLineWidth", TopologyAttributes_GetLineWidth, METH_VARARGS},
    {"SetMultiColor", TopologyAttributes_SetMultiColor, METH_VARARGS},
    {"GetMultiColor", TopologyAttributes_GetMultiColor, METH_VARARGS},
    {"SetMinOpacity", TopologyAttributes_SetMinOpacity, METH_VARARGS},
    {"GetMinOpacity", TopologyAttributes_GetMinOpacity, METH_VARARGS},
    {"SetMinPlateauOpacity", TopologyAttributes_SetMinPlateauOpacity, METH_VARARGS},
    {"GetMinPlateauOpacity", TopologyAttributes_GetMinPlateauOpacity, METH_VARARGS},
    {"SetMaxPlateauOpacity", TopologyAttributes_SetMaxPlateauOpacity, METH_VARARGS},
    {"GetMaxPlateauOpacity", TopologyAttributes_GetMaxPlateauOpacity, METH_VARARGS},
    {"SetMaxOpacity", TopologyAttributes_SetMaxOpacity, METH_VARARGS},
    {"GetMaxOpacity", TopologyAttributes_GetMaxOpacity, METH_VARARGS},
    {"SetTolerance", TopologyAttributes_SetTolerance, METH_VARARGS},
    {"GetTolerance", TopologyAttributes_GetTolerance, METH_VARARGS},
    {"SetHitpercent", TopologyAttributes_SetHitpercent, METH_VARARGS},
    {"GetHitpercent", TopologyAttributes_GetHitpercent, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
TopologyAttributes_dealloc(PyObject *v)
{
   TopologyAttributesObject *obj = (TopologyAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *TopologyAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyTopologyAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "lineWidth") == 0)
        return TopologyAttributes_GetLineWidth(self, NULL);
    if(strcmp(name, "multiColor") == 0)
        return TopologyAttributes_GetMultiColor(self, NULL);
    if(strcmp(name, "minOpacity") == 0)
        return TopologyAttributes_GetMinOpacity(self, NULL);
    if(strcmp(name, "minPlateauOpacity") == 0)
        return TopologyAttributes_GetMinPlateauOpacity(self, NULL);
    if(strcmp(name, "maxPlateauOpacity") == 0)
        return TopologyAttributes_GetMaxPlateauOpacity(self, NULL);
    if(strcmp(name, "maxOpacity") == 0)
        return TopologyAttributes_GetMaxOpacity(self, NULL);
    if(strcmp(name, "tolerance") == 0)
        return TopologyAttributes_GetTolerance(self, NULL);
    if(strcmp(name, "hitpercent") == 0)
        return TopologyAttributes_GetHitpercent(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyTopologyAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyTopologyAttributes_methods[i].ml_name),
                PyString_FromString(PyTopologyAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyTopologyAttributes_methods, self, name);
}

int
PyTopologyAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "lineWidth") == 0)
        obj = TopologyAttributes_SetLineWidth(self, args);
    else if(strcmp(name, "multiColor") == 0)
        obj = TopologyAttributes_SetMultiColor(self, args);
    else if(strcmp(name, "minOpacity") == 0)
        obj = TopologyAttributes_SetMinOpacity(self, args);
    else if(strcmp(name, "minPlateauOpacity") == 0)
        obj = TopologyAttributes_SetMinPlateauOpacity(self, args);
    else if(strcmp(name, "maxPlateauOpacity") == 0)
        obj = TopologyAttributes_SetMaxPlateauOpacity(self, args);
    else if(strcmp(name, "maxOpacity") == 0)
        obj = TopologyAttributes_SetMaxOpacity(self, args);
    else if(strcmp(name, "tolerance") == 0)
        obj = TopologyAttributes_SetTolerance(self, args);
    else if(strcmp(name, "hitpercent") == 0)
        obj = TopologyAttributes_SetHitpercent(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
TopologyAttributes_print(PyObject *v, FILE *fp, int flags)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)v;
    fprintf(fp, "%s", PyTopologyAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
TopologyAttributes_str(PyObject *v)
{
    TopologyAttributesObject *obj = (TopologyAttributesObject *)v;
    return PyString_FromString(PyTopologyAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *TopologyAttributes_Purpose = "This class contains the plot attributes for the topology plot";
#else
static char *TopologyAttributes_Purpose = "This class contains the plot attributes for the topology plot";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(TopologyAttributesType,         \
                  "TopologyAttributes",           \
                  TopologyAttributesObject,       \
                  TopologyAttributes_dealloc,     \
                  TopologyAttributes_print,       \
                  PyTopologyAttributes_getattr,   \
                  PyTopologyAttributes_setattr,   \
                  TopologyAttributes_str,         \
                  TopologyAttributes_Purpose,     \
                  TopologyAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
TopologyAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &TopologyAttributesType
         || Py_TYPE(other) != &TopologyAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    TopologyAttributes *a = ((TopologyAttributesObject *)self)->data;
    TopologyAttributes *b = ((TopologyAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static TopologyAttributes *defaultAtts = 0;
static TopologyAttributes *currentAtts = 0;

static PyObject *
NewTopologyAttributes(int useCurrent)
{
    TopologyAttributesObject *newObject;
    newObject = PyObject_NEW(TopologyAttributesObject, &TopologyAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new TopologyAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new TopologyAttributes(*defaultAtts);
    else
        newObject->data = new TopologyAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapTopologyAttributes(const TopologyAttributes *attr)
{
    TopologyAttributesObject *newObject;
    newObject = PyObject_NEW(TopologyAttributesObject, &TopologyAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (TopologyAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
TopologyAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewTopologyAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef TopologyAttributesMethods[] = {
    {"TopologyAttributes", TopologyAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *TopologyAttributesObserver = 0;

std::string
PyTopologyAttributes_GetLogString()
{
    std::string s("TopologyAtts = TopologyAttributes()\n");
    if(currentAtts != 0)
        s += PyTopologyAttributes_ToString(currentAtts, "TopologyAtts.", true);
    return s;
}

static void
PyTopologyAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("TopologyAtts = TopologyAttributes()\n");
        s += PyTopologyAttributes_ToString(currentAtts, "TopologyAtts.", true);
        cb(s);
    }
}

void
PyTopologyAttributes_StartUp(TopologyAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyTopologyAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(TopologyAttributesObserver == 0)
    {
        TopologyAttributesObserver = new ObserverToCallback(subj,
            PyTopologyAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyTopologyAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete TopologyAttributesObserver;
    TopologyAttributesObserver = 0;
}

PyMethodDef *
PyTopologyAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return TopologyAttributesMethods;
}

bool
PyTopologyAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &TopologyAttributesType);
}

TopologyAttributes *
PyTopologyAttributes_FromPyObject(PyObject *obj)
{
    TopologyAttributesObject *obj2 = (TopologyAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyTopologyAttributes_New()
{
    return NewTopologyAttributes(0);
}

PyObject *
PyTopologyAttributes_Wrap(const TopologyAttributes *attr)
{
    return WrapTopologyAttributes(attr);
}

void
PyTopologyAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    TopologyAttributesObject *obj2 = (TopologyAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyTopologyAttributes_SetDefaults(const TopologyAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new TopologyAttributes(*atts);
}

